<?php

/**
 * lzp300 2015-01-27
 */
class system extends actionAbstract {

    /**
     * 构造
     */
    function __construct() {
        parent::__construct();
        $this->cityItem = $this->getCity();
        if (!isset($_COOKIE['qingMg_admininfo'])) {
            header('location:' . $this->url('common/login'));
        }
    }

    //密码修改
    function upPwd() {
        $this->loadModel('system', 'account');
        $password = isset($_POST['password']) ? trim($_POST['password']) : '';
        $pwd = isset($_POST['pwd']) ? trim($_POST['pwd']) : '';
        if (!$password) {
            exit(json_encode(array('state' => 0, 'html' => '请填写密码')));
        }
        if (!$pwd) {
            exit(json_encode(array('state' => 0, 'html' => '请填写确认密码')));
        }
        if ($password != $pwd) {
            exit(json_encode(array('state' => 0, 'html' => '两次密码不一致')));
        }
        $data['password'] = md5($pwd);
        $data['createtime'] = time();
        $re = $this->system->accountModel->update($data, "id=" . $_SESSION['qingMg_admininfo']['id']);
        if ($re) {
            unset($_SESSION['qingMg_admininfo']);
            exit(json_encode(array('state' => 1, 'html' => '修改成功，2秒后返回到登录页面', 'url' => $this->url('common/login'))));
        } else {
            exit(json_encode(array('state' => 0, 'html' => '修改失败')));
        }
    }

    //账号管理
    function account() {
        $page = isset($_GET['page']) ? ((int) ($_GET['page']) ? (int) ($_GET['page']) : 1) : 1;
        $keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';

        $sql_from = " from system_account ";
        $sql_where = "";
        $sql_order_by = " order by createtime desc";
        $field_reto = " count(*)";
        $field_re = " * ";

        if ($keywords) {
            $keywordsArr = explode(',', $keywords);
            $sql_where.=" where (";
            foreach ($keywordsArr as $k => $v) {
                if ($k == 0) {
                    $sql_where.="username like '%" . trim($v) . "%'";
                } else {
                    $sql_where.=" or username like '%" . trim($v) . "%'";
                }
            }
            $sql_where.=")";
        }

        $return = $this->getPage($sql_from, $sql_where, $sql_order_by, $field_reto, $field_re, "system", "account", $page, 10);
        $re = $return['re'];
        $number = $return['number'];
        $pageHtml = $return['pageHtml'];
        //echo "<pre>";print_r($re);exit;

        include $this->loadWidget('masterTheme');
    }

    //账号添加、修改
    function upAccount() {
        $this->loadModel('system', 'account');
        $username = isset($_POST['username']) ? trim($_POST['username']) : '';
        $password = isset($_POST['password']) ? trim($_POST['password']) : '';
        $pwd = isset($_POST['pwd']) ? trim($_POST['pwd']) : '';
        $status = isset($_POST['status']) ? (int) ($_POST['status']) : 2;
        $kid = isset($_POST['kid']) ? (int) ($_POST['kid']) : 0;
        if (!$username) {
            exit(json_encode(array('state' => 0, 'html' => '请填写账号')));
        }
        if (!$kid && (!$password || !$pwd)) {
            exit(json_encode(array('state' => 0, 'html' => '请填写密码')));
        }
        if (($password || $pwd) && $password != $pwd) {
            exit(json_encode(array('state' => 0, 'html' => '两次密码不一致')));
        } elseif ($password && $pwd && $password == $pwd) {
            $data['password'] = md5($pwd);
        }

        $checkName = $this->system->accountModel->fetchRow("select id from sys_account where id!=$kid and username='" . $username . "'");
        if ($checkName) {
            exit(json_encode(array('state' => 0, 'html' => '该账号已存在')));
        }

        $data['status'] = $status;
        $data['createtime'] = time();

        $re = "";
        if ($kid) {
            $re = $this->system->accountModel->update($data, "id=$kid");
        } else {
            $data['username'] = $username;
            $re = $this->system->accountModel->insert($data);
        }

        if ($re) {
            exit(json_encode(array('state' => 1, 'html' => ($kid ? '修改成功' : '添加成功') . '，2秒后自动刷新')));
        } else {
            exit(json_encode(array('state' => 0, 'html' => ($kid ? '修改失败' : '添加失败'))));
        }
    }

    //删除账号
    function delAccount() {
        $this->loadModel('system', 'account');
        $kid = isset($_POST['kid']) ? (int) ($_POST['kid']) : 0;
        $re = $this->system->accountModel->delete("id=$kid");
        if ($re) {
            exit(json_encode(array('state' => 1, 'html' => '删除成功，2秒后自动刷新')));
        } else {
            exit(json_encode(array('state' => 0, 'html' => '删除失败')));
        }
    }

    //菜单管理
    function menu() {
        $this->loadHelper('extend');
        //echo "<pre>";print_r($this->homeMenu);exit;
        include $this->loadWidget('masterTheme');
    }

    //添加、修改菜单
    function upMenu() {
        $this->loadModel('system', 'menu');
        $kid = isset($_POST['kid']) ? (int) ($_POST['kid']) : 0;
        $data['model'] = isset($_POST['model']) ? (int) ($_POST['model']) : 0;
        $data['parentid'] = isset($_POST['parentid']) ? (int) ($_POST['parentid']) : 0;
        $data['sort'] = isset($_POST['sort']) ? ((int) ($_POST['sort']) ? (int) ($_POST['sort']) : 9999) : 9999;
        $data['status'] = isset($_POST['status']) ? (int) ($_POST['status']) : 0;
        $data['isaction'] = isset($_POST['isaction']) ? (int) ($_POST['isaction']) : 0;
        $title = isset($_POST['title']) ? trim($_POST['title']) : '';
        $url = isset($_POST['url']) ? trim($_POST['url']) : '';
        $icon = isset($_POST['icon']) ? trim($_POST['icon']) : '';
        $bewrite = isset($_POST['bewrite']) ? trim($_POST['bewrite']) : '';
        if (!$title) {
            exit(json_encode(array('state' => 0, 'html' => '请填写菜单名称')));
        }
        if (!$url) {
            exit(json_encode(array('state' => 0, 'html' => '请填写菜单路径')));
        }
        if (!$data['parentid'] && !$icon) {
            exit(json_encode(array('state' => 0, 'html' => '请填写菜单图标')));
        }
        $data['title'] = $title;
        $data['url'] = $url;
        $data['icon'] = $icon;
        $data['bewrite'] = $bewrite;
        $data['created'] = date('Y-m-d H:i:s', time());

        $re = "";
        if ($kid) {
            $re = $this->system->menuModel->update($data, "id=$kid");
        } else {
            $re = $this->system->menuModel->insert($data);
        }
        if ($re) {
            exit(json_encode(array('state' => 1, 'html' => ($kid ? '修改成功' : '添加成功') . '，2秒后自动刷新')));
        } else {
            exit(json_encode(array('state' => 0, 'html' => ($kid ? '修改失败' : '添加失败'))));
        }
    }

    //删除菜单
    function delMenu() {
        $this->loadModel('system', 'menu');
        $kid = isset($_POST['kid']) ? (int) ($_POST['kid']) : 0;
        $re = $this->system->menuModel->delete("id=$kid or parentid=$kid");
        if ($re) {
            exit(json_encode(array('state' => 1, 'html' => '删除成功，2秒后自动刷新')));
        } else {
            exit(json_encode(array('state' => 0, 'html' => '删除失败')));
        }
    }

    //更新酒店
    function gethotel() {
		$page=isset($_GET['page'])?((int)($_GET['page'])?(int)($_GET['page']):1):1;
		$keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';
		
		$str="28,53,72,85,16425,16615,16736,103,356,727,1188,1458,2624,2718,3206,4199,4216,4334,4416,4519,5583,6276,6452,6762,7612,16805,17207,18040,18901,7820,7855,7856,7961,18925,19137,19215,19271,19352,19565,19652,19818,19955,20234,20264,20334,20410,20766,21212,21359,21534,22054,22337,22360,8080,8105,8134,8148,8270,8323,8400,8494,9119,9201,9390,9929,10128,10236,10252,10412,10528,10551,10745,10766,10946,10963,11042,11135,11211,11432,11605,11662,12160,12166,12350,12373,12612,12662,13229,13406,13591,13732,14183,15284,22552,23171,25240,25487,15502,15531,15909,16057,25559,25833,25867,26146,26320,26357,26622,27000,27036,27354,27609,16201,16376,16391,16413,29823,30071,30183,30240,30282,30408,30449,30526,27966,28100,28227,35575,30773,31546,31568,31750,31883,32033,32341,32399,32495,32783,33119,33622,34171,36143,36384,38772,39105,44858,45444,45544,45905,45912,45958,46193,46239,39519,39633,40416,41045,46268,46475,46524,46610,46675,46806,46829,46883,41179,41357,41382,41536,41617,42702,42933,43104,43106,43121,43541,43743,47455,47669,47906,48196,48609,44352,44377,50771,50800,50989,51032,51087,51185,51204,51396,51425,51627,53250,53289,48724,48907,48993,49193,53399,53430,53733,53811,53837,53877,54004,54143,54245,54249,54279,54399,54526,56604,56644,56845,56992,49201,49270,49646,50589,57030,57088,57523,57641,58250,58272,58399,58548,58562,58737,59423,59491,59498,59544,59566,62946,63028,63042,67812,67842,68041,68271,68388,68815,63189,63375,65838,65880,74992,75139,75169,75538,75652,75668,75671,75736,75837,66932,67108,67299,67665,75857,75870,75893,75897,67668,67751,79259,79292,79350,79404,80259,80425,82607,87835,87856,87861,87867,87887,88041,88052,88194,88222,75899,77376,77520,77624,94231,94263,94314,94341,94372,94759,88364,88406,88422,88542,88668,88761,88784,88823,88893,95490,95510,95523,95527,95949,95950,95984,95990,95997,96234,96242,96313,96340,88913,97747,97770,97785,97800,97805,97821,97831,97836,96396,96408,96411,101520,101551,101566,101567,101569,101610,101612,101793,101892,101922,102008,97847,97854,97861,97862,98558,103233,103280,103294,103313,98567,105525,105547,105613,105622,106094,106137,106154,106170,103345,104093,104503,130545,106201,107801,107847,107875,108163,108164,108168,108202,108224,130580,131038,131079,131080,131081,131087,136272,136280,108226,116189,127999,128214,129432,139391,144995,145021,145412,145442,129973,147575,147643,147659,147707,145504,145667,146193,146213,147724,147784,147849,147921,146288,146300,146349,146359,146384,146984,147146,147153,147203,147208,147230,149172,151145,151678,151944,152187,152296,152314,152353,47640730,6342,36605,39502,32264,166781,5234,32270,96413,4777,50940,161686,31590,53409,57128,162392,88752,73969,32273,29597,14762,67022,68482,94242,13209,152324,58507,35742,31811,97463,47637,149168,40287,166788,48759,57,813,10121,75373,75567,8245,9907,155803,68230,77350,88598,130452,130503,130531,130584,75890,44573,7793,14917,87851,12464,166779,145345,146224,63289,152327,116176,75898,147619,75767,145374,107834,108156,128060,75868,75882,79272,145694,88497,128238,146272,147294,15431,79386,15425,20961,147778,75986,145642,146261,32579,162951,151132,68451,101938,146146,128089,17492,146330,79273,79283,147658,147775,68107,75873,79125,147251,101628,145436,147670,96230,152177,68539,145333";
		$str=explode(',',$str);
		$in="";
		foreach($str as $k=>$v){
			$in.="'".$v."',";
		}
		$in=trim($in,",");
		
		$sql_from=" from qm_hotel";
		$sql_where=" where `name`!='' and osiiCityID>0 and osiiCountyID>0 and osiiProvinceID>0 and hid in (".$in.")";
		$sql_order_by=" ";
		$field_reto=" count(hid)";
		$field_re=" hid,`name`,address,osiiCityID,osiiCityName,osiiCountyID,osiiCountyName,osiiProvinceID,osiiProvinceName,tjgradenum,created ";
		
		if($keywords){
            $keywordsArr=explode(',',$keywords);
			$sql_where.=" and (";
            foreach($keywordsArr as $k=>$v){
				if($k==0){$sql_where.="name like '%".trim($v)."%' or osiiProvinceName like '%".trim($v)."%' or osiiCityName like '%".trim($v)."%' or osiiCountyName like '%".trim($v)."%'";}
				else{$sql_where.=" or name like '%".trim($v)."%' or osiiProvinceName like '%".trim($v)."%' or osiiCityName like '%".trim($v)."%' or osiiCountyName like '%".trim($v)."%'";}
            }	
			$sql_where.=")";
        }
		
		$return=$this->getPage($sql_from,$sql_where,$sql_order_by,$field_reto,$field_re,"qm","hotel",$page,10);
		$re=$return['re'];$number=$return['number'];$pageHtml=$return['pageHtml'];
		
        include $this->loadWidget('masterTheme');
    }
	
	//更新房型
    function gettype() {
        $keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';
        $page = isset($_GET['page']) ? ((int) ($_GET['page']) ? (int) ($_GET['page']) : 1) : 1;
		
		$str="28,53,72,85,16425,16615,16736,103,356,727,1188,1458,2624,2718,3206,4199,4216,4334,4416,4519,5583,6276,6452,6762,7612,16805,17207,18040,18901,7820,7855,7856,7961,18925,19137,19215,19271,19352,19565,19652,19818,19955,20234,20264,20334,20410,20766,21212,21359,21534,22054,22337,22360,8080,8105,8134,8148,8270,8323,8400,8494,9119,9201,9390,9929,10128,10236,10252,10412,10528,10551,10745,10766,10946,10963,11042,11135,11211,11432,11605,11662,12160,12166,12350,12373,12612,12662,13229,13406,13591,13732,14183,15284,22552,23171,25240,25487,15502,15531,15909,16057,25559,25833,25867,26146,26320,26357,26622,27000,27036,27354,27609,16201,16376,16391,16413,29823,30071,30183,30240,30282,30408,30449,30526,27966,28100,28227,35575,30773,31546,31568,31750,31883,32033,32341,32399,32495,32783,33119,33622,34171,36143,36384,38772,39105,44858,45444,45544,45905,45912,45958,46193,46239,39519,39633,40416,41045,46268,46475,46524,46610,46675,46806,46829,46883,41179,41357,41382,41536,41617,42702,42933,43104,43106,43121,43541,43743,47455,47669,47906,48196,48609,44352,44377,50771,50800,50989,51032,51087,51185,51204,51396,51425,51627,53250,53289,48724,48907,48993,49193,53399,53430,53733,53811,53837,53877,54004,54143,54245,54249,54279,54399,54526,56604,56644,56845,56992,49201,49270,49646,50589,57030,57088,57523,57641,58250,58272,58399,58548,58562,58737,59423,59491,59498,59544,59566,62946,63028,63042,67812,67842,68041,68271,68388,68815,63189,63375,65838,65880,74992,75139,75169,75538,75652,75668,75671,75736,75837,66932,67108,67299,67665,75857,75870,75893,75897,67668,67751,79259,79292,79350,79404,80259,80425,82607,87835,87856,87861,87867,87887,88041,88052,88194,88222,75899,77376,77520,77624,94231,94263,94314,94341,94372,94759,88364,88406,88422,88542,88668,88761,88784,88823,88893,95490,95510,95523,95527,95949,95950,95984,95990,95997,96234,96242,96313,96340,88913,97747,97770,97785,97800,97805,97821,97831,97836,96396,96408,96411,101520,101551,101566,101567,101569,101610,101612,101793,101892,101922,102008,97847,97854,97861,97862,98558,103233,103280,103294,103313,98567,105525,105547,105613,105622,106094,106137,106154,106170,103345,104093,104503,130545,106201,107801,107847,107875,108163,108164,108168,108202,108224,130580,131038,131079,131080,131081,131087,136272,136280,108226,116189,127999,128214,129432,139391,144995,145021,145412,145442,129973,147575,147643,147659,147707,145504,145667,146193,146213,147724,147784,147849,147921,146288,146300,146349,146359,146384,146984,147146,147153,147203,147208,147230,149172,151145,151678,151944,152187,152296,152314,152353";
		$str=explode(',',$str);
		$in="";
		foreach($str as $k=>$v){
			$in.="'".$v."',";
		}
		$in=trim($in,",");
		
		$sql_from=" from qm_room as a left join qm_hotel as b on b.hid=a.hid";
		$sql_where=" where a.`name`!='' and a.hid in (".$in.")";
		$sql_order_by=" ";
		$field_reto=" count(a.hid)";
		$field_re=" a.*,b.name as hName ";
		
		if($keywords){
            $keywordsArr=explode(',',$keywords);
			$sql_where.=" and (";
            foreach($keywordsArr as $k=>$v){
				if($k==0){$sql_where.="a.name like '%".trim($v)."%' or b.name like '%".trim($v)."%'";}
				else{$sql_where.=" or a.name like '%".trim($v)."%' or b.name like '%".trim($v)."%'";}
            }	
			$sql_where.=")";
        }
		
		$return=$this->getPage($sql_from,$sql_where,$sql_order_by,$field_reto,$field_re,"qm","room",$page,10);
		$re=$return['re'];$number=$return['number'];$pageHtml=$return['pageHtml'];
        
        include $this->loadWidget('masterTheme');
    }
	
	//更新图片
    function getpictrure() {
		$keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';
        $page = isset($_GET['page']) ? ((int) ($_GET['page']) ? (int) ($_GET['page']) : 1) : 1;
		
		$str="28,53,72,85,16425,16615,16736,103,356,727,1188,1458,2624,2718,3206,4199,4216,4334,4416,4519,5583,6276,6452,6762,7612,16805,17207,18040,18901,7820,7855,7856,7961,18925,19137,19215,19271,19352,19565,19652,19818,19955,20234,20264,20334,20410,20766,21212,21359,21534,22054,22337,22360,8080,8105,8134,8148,8270,8323,8400,8494,9119,9201,9390,9929,10128,10236,10252,10412,10528,10551,10745,10766,10946,10963,11042,11135,11211,11432,11605,11662,12160,12166,12350,12373,12612,12662,13229,13406,13591,13732,14183,15284,22552,23171,25240,25487,15502,15531,15909,16057,25559,25833,25867,26146,26320,26357,26622,27000,27036,27354,27609,16201,16376,16391,16413,29823,30071,30183,30240,30282,30408,30449,30526,27966,28100,28227,35575,30773,31546,31568,31750,31883,32033,32341,32399,32495,32783,33119,33622,34171,36143,36384,38772,39105,44858,45444,45544,45905,45912,45958,46193,46239,39519,39633,40416,41045,46268,46475,46524,46610,46675,46806,46829,46883,41179,41357,41382,41536,41617,42702,42933,43104,43106,43121,43541,43743,47455,47669,47906,48196,48609,44352,44377,50771,50800,50989,51032,51087,51185,51204,51396,51425,51627,53250,53289,48724,48907,48993,49193,53399,53430,53733,53811,53837,53877,54004,54143,54245,54249,54279,54399,54526,56604,56644,56845,56992,49201,49270,49646,50589,57030,57088,57523,57641,58250,58272,58399,58548,58562,58737,59423,59491,59498,59544,59566,62946,63028,63042,67812,67842,68041,68271,68388,68815,63189,63375,65838,65880,74992,75139,75169,75538,75652,75668,75671,75736,75837,66932,67108,67299,67665,75857,75870,75893,75897,67668,67751,79259,79292,79350,79404,80259,80425,82607,87835,87856,87861,87867,87887,88041,88052,88194,88222,75899,77376,77520,77624,94231,94263,94314,94341,94372,94759,88364,88406,88422,88542,88668,88761,88784,88823,88893,95490,95510,95523,95527,95949,95950,95984,95990,95997,96234,96242,96313,96340,88913,97747,97770,97785,97800,97805,97821,97831,97836,96396,96408,96411,101520,101551,101566,101567,101569,101610,101612,101793,101892,101922,102008,97847,97854,97861,97862,98558,103233,103280,103294,103313,98567,105525,105547,105613,105622,106094,106137,106154,106170,103345,104093,104503,130545,106201,107801,107847,107875,108163,108164,108168,108202,108224,130580,131038,131079,131080,131081,131087,136272,136280,108226,116189,127999,128214,129432,139391,144995,145021,145412,145442,129973,147575,147643,147659,147707,145504,145667,146193,146213,147724,147784,147849,147921,146288,146300,146349,146359,146384,146984,147146,147153,147203,147208,147230,149172,151145,151678,151944,152187,152296,152314,152353";
		$str=explode(',',$str);
		$in="";
		foreach($str as $k=>$v){
			$in.="'".$v."',";
		}
		$in=trim($in,",");
		
		$sql_from=" from qm_image as a left join qm_hotel as b on b.hid=a.hid";
		$sql_where=" where a.`url`!='' and a.hid in (".$in.")";
		$sql_order_by=" ";
		$field_reto=" count(a.hid)";
		$field_re=" a.*,b.name as hName ";
		
		if($keywords){
            $keywordsArr=explode(',',$keywords);
			$sql_where.=" and (";
            foreach($keywordsArr as $k=>$v){
				if($k==0){$sql_where.="a.title like '%".trim($v)."%' or b.name like '%".trim($v)."%'";}
				else{$sql_where.=" or a.title like '%".trim($v)."%' or b.name like '%".trim($v)."%'";}
            }	
			$sql_where.=")";
        }
		
		$return=$this->getPage($sql_from,$sql_where,$sql_order_by,$field_reto,$field_re,"qm","image",$page,10);
		$re=$return['re'];$number=$return['number'];$pageHtml=$return['pageHtml'];
		
        include $this->loadWidget('masterTheme');
    }
	
	//更新房态
	function upTypeStaus(){
		$hotelName = isset($_GET['hotelName']) ? trim($_GET['hotelName']) : '';
		$hotelCode = isset($_GET['hotelCode']) ? trim($_GET['hotelCode']) : '';
		$typeName = isset($_GET['typeName']) ? trim($_GET['typeName']) : '';
		$typeCode = isset($_GET['typeCode']) ? trim($_GET['typeCode']) : '';
		$start = isset($_GET['start']) ? trim($_GET['start']) : '';
		$end = isset($_GET['end']) ? trim($_GET['end']) : '';
        $page = isset($_GET['page']) ? ((int) ($_GET['page']) ? (int) ($_GET['page']) : 1) : 1;
		
		$sql_from=" from qm_roombatch as a left join qm_hotel as b on b.hid=a.hid left join qm_room as c on c.rid=a.rid and c.hid=a.hid";
		$sql_where=" where a.price>0 and b.id >=3074 and a.date>='".date('Y-m-d',time())."'";
		$sql_order_by=" order by a.hid,a.rid,a.date asc";
		$field_reto=" count(a.hid)";
		$field_re=" a.*,b.name as hName,c.name as tName";
		
		if($hotelName){$sql_where.=" and b.name like '%".$hotelName."%'";}
		if($hotelCode){$sql_where.=" and a.hid='".$hotelCode."'";}
		if($typeName){$sql_where.=" and c.name like '%".$typeName."%'";}
		if($typeCode){$sql_where.=" and a.rid='".$typeCode."'";}
		if($start){$sql_where.=" and a.date>='".$start."'";}
		if($end){$sql_where.=" and a.date<='".$end."'";}
		
		$return=$this->getPage($sql_from,$sql_where,$sql_order_by,$field_reto,$field_re,"qm","room",$page,10);
		$re=$return['re'];$number=$return['number'];$pageHtml=$return['pageHtml'];
        
		$this->loadModel('qm','channels');
		$channels=$this->qm->channelsModel->fetchAll("select * from qm_channels where otastatus=1 and status=1");
		
        include $this->loadWidget('masterTheme');
	}
	
	//酒店搜索
	function serachHotel(){
		$this->loadModel('qm','hotel');
		$keyword=isset($_POST['keyword'])?trim($_POST['keyword']):'';
		if(!$keyword){exit(json_encode(array('state'=>0,'html'=>'请填写关键字')));}
		
		$re=$this->qm->hotelModel->fetchAll("select hid,name from qm_hotel where name like '%".$keyword."%' and id>=3074");
		if($re){
			$html="<option value='0'>请选择酒店</option>";
			foreach($re as $k=>$v){
				$html.="<option value='".$v['hid']."'>".$v['name']."</option>";
			}
			exit(json_encode(array('state'=>1,'html'=>$html)));
		}
		exit(json_encode(array('state'=>0,'html'=>"没有相关酒店")));
	}
	//房型搜索
	function serachRoom(){
		$this->loadModel('qm','room');
		$hid=isset($_POST['hid'])?(int)($_POST['hid']):0;
		
		$sql="select a.rid,a.name from qm_room as a left join qm_hotel as b on b.hid=a.hid where b.id>=3074 and a.hid=$hid";
		$re=$this->qm->roomModel->fetchAll($sql);
		if($re){
			$html="<option value='0'>请选择房型</option>";
			foreach($re as $k=>$v){
				$html.="<option value='".$v['rid']."'>".$v['name']."</option>";
			}
			exit(json_encode(array('state'=>1,'html'=>$html)));
		}
		exit(json_encode(array('state'=>0,'html'=>"没有相关房型")));
	}
	
	//更新渠道
	function channels(){
		$keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';
        $page = isset($_GET['page']) ? ((int) ($_GET['page']) ? (int) ($_GET['page']) : 1) : 1;
		
		$sql_from=" from qm_channels";
		$sql_where="";
		$sql_order_by=" order by status desc";
		$field_reto=" count(osiiid)";
		$field_re=" *";
		
		if($keywords){
            $keywordsArr=explode(',',$keywords);
			$sql_where.=" where (";
            foreach($keywordsArr as $k=>$v){
				if($k==0){$sql_where.="title like '%".trim($v)."%' or osiiid like '%".trim($v)."%'";}
				else{$sql_where.=" or title like '%".trim($v)."%' or osiiid like '%".trim($v)."%'";}
            }	
			$sql_where.=")";
        }
		
		$return=$this->getPage($sql_from,$sql_where,$sql_order_by,$field_reto,$field_re,"qm","channels",$page,10);
		$re=$return['re'];$number=$return['number'];$pageHtml=$return['pageHtml'];
		
		include $this->loadWidget('masterTheme');
	}
	//开关渠道
	function upChannels(){
		$this->loadModel('qm','channels');
		$kid=isset($_POST['kid'])?(int)($_POST['kid']):0;
		$sq=$this->qm->channelsModel->fetchRow("select status from qm_channels where id=$kid");
		if($sq){
			$sq['status']==0?$data['status']=1:$data['status']=0;
			$re=$this->qm->channelsModel->update($data,"id=$kid");
			exit(json_encode(array('state' => 1, 'html' => '修改成功，2秒后自动刷新！')));
		}
		exit(json_encode(array('state' => 0, 'html' => '修改失败')));
	}
	
	
	
	
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //获取市、区
    function getTc() {
        $this->loadModel('tc', 'city');
        $this->loadModel('tc', 'county');
        $parentid = isset($_POST['parentid']) ? (int) $_POST['parentid'] : 0;
        $type = isset($_POST['type']) ? (int) ($_POST['type']) : 0;
        if ($type == 1) {
            $re = $this->tc->cityModel->fetchAll("select * from tc_city where province_id=$parentid");
        } elseif ($type == 2) {
            $re = $this->tc->countyModel->fetchAll("select * from tc_county where city_id=$parentid");
        }
        $html = "";
        $html.="<option value='0'>请选择</option>";
        if ($re) {
            foreach ($re as $k => $v) {
                $html.="<option value='" . $v['osiiid'] . "'>" . $v['name'] . "</option>";
            }
        }
        exit(json_encode(array('type' => $type, 'html' => $html)));
    }

    //更新城市
    function getCityList() {
        $this->loadModel('qm', 'city');
        $page = isset($_GET['page']) ? ((int) ($_GET['page']) ? (int) ($_GET['page']) : 1) : 1;
		$keywords=isset($_GET['keywords'])?trim($_GET['keywords']):'';
		
        $sql_from = " from qm_city ";
        $sql_where = "";
        $sql_order_by = " order by cid asc";
        $field_reto = " count(*)";
        $field_re = " * ";
		
		if($keywords){
            $keywordsArr=explode(',',$keywords);
			$sql_where.=" where (";
            foreach($keywordsArr as $k=>$v){
				if($k==0){$sql_where.=" name like '%".trim($v)."%' or pinyin like '%".trim($v)."%' or suoxie like '%".trim($v)."%' or code like '%".trim($v)."%'";}
				else{$sql_where.=" or name like '%".trim($v)."%' or pinyin like '%".trim($v)."%' or suoxie like '%".trim($v)."%' or code like '%".trim($v)."%'";}
            }	
			$sql_where.=")";
        }
		
        $return = $this->getPage($sql_from, $sql_where, $sql_order_by, $field_reto, $field_re, "qm", "city", $page, 10);
        $re = $return['re'];
        $number = $return['number'];
        $pageHtml = $return['pageHtml'];
        include $this->loadWidget('masterTheme');
    }

    //更新区域
    function getAreaList() {
        $this->loadModel('qm', 'area');
        $page = isset($_GET['page']) ? ((int) ($_GET['page']) ? (int) ($_GET['page']) : 1) : 1;
		$keywords=isset($_GET['keywords'])?trim($_GET['keywords']):'';
		
        $sql_from = " from qm_area as a LEFT JOIN qm_city as c on c.cid=a.cid";
        $sql_where = "";
        $sql_order_by = " order by a.cid asc";
        $field_reto = " count(*)";
        $field_re = " a.*,c.name as cname ";
		
		if($keywords){
            $keywordsArr=explode(',',$keywords);
			$sql_where.=" where (";
            foreach($keywordsArr as $k=>$v){
				if($k==0){$sql_where.=" a.name like '%".trim($v)."%' or a.pinyin like '%".trim($v)."%' or a.suoxie like '%".trim($v)."%' or c.name like '%".trim($v)."%'";}
				else{$sql_where.=" or a.name like '%".trim($v)."%' or a.pinyin like '%".trim($v)."%' or a.suoxie like '%".trim($v)."%' or c.name like '%".trim($v)."%'";}
            }	
			$sql_where.=")";
        }
		
        $return = $this->getPage($sql_from, $sql_where, $sql_order_by, $field_reto, $field_re, "qm", "area", $page, 10);
        $re = $return['re'];
        $number = $return['number'];
        $pageHtml = $return['pageHtml'];
        include $this->loadWidget('masterTheme');
    }

    //更新地标
    function getTagList() {
        global $myconfigs;
        $this->loadModel('qm', 'tag');
        $page = isset($_GET['page']) ? ((int) ($_GET['page']) ? (int) ($_GET['page']) : 1) : 1;
		$keywords=isset($_GET['keywords'])?trim($_GET['keywords']):'';
		
        $sql_from = " from qm_tag as a LEFT JOIN qm_city as c on c.cid=a.cid";
        $sql_where = "";
        $sql_order_by = " order by a.tid asc";
        $field_reto = " count(*)";
        $field_re = " a.*,c.name as cname ";
		
		if($keywords){
            $keywordsArr=explode(',',$keywords);
			$sql_where.=" where (";
            foreach($keywordsArr as $k=>$v){
				if($k==0){$sql_where.=" a.name like '%".trim($v)."%' or c.name like '%".trim($v)."%'";}
				else{$sql_where.=" or a.name like '%".trim($v)."%' or c.name like '%".trim($v)."%'";}
            }	
			$sql_where.=")";
        }
		
        $return = $this->getPage($sql_from, $sql_where, $sql_order_by, $field_reto, $field_re, "qm", "tag", $page, 10);
        $re = $return['re'];
        $number = $return['number'];
        $pageHtml = $return['pageHtml'];
        include $this->loadWidget('masterTheme');
    }

}
